package com.sky.mapper;

import com.sky.entity.ShoppingCart;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

@Mapper
public interface ShoppingCartMapper {
    /**
     * 条件查询
     * @return
     */
    List<ShoppingCart> select(ShoppingCart shoppingCart);

    /**
     * 更新购物车信息，目前主要功能就是让购物车中物品数量加减
     * @param cart
     */
    void update(ShoppingCart cart);

    /**
     * 插入一条信息
     * @param shoppingCart
     */
    @Insert("insert into shopping_cart(name, image, user_id, dish_id, setmeal_id, dish_flavor, amount, create_time) " +
            "value(#{name}, #{image}, #{userId}, #{dishId}, #{setmealId}, #{dishFlavor},#{amount}, #{createTime} )")
    void insert(ShoppingCart shoppingCart);

    /**
     * 清空购物车
     * @param userId
     */
    @Delete("delete from shopping_cart where user_id = #{userId}")
    void deleteByUserId(Long userId);
}
